<template>
  <div class="brand-list">
    <div id="J-productList" class="auc_order">
      <p>
        <a href="javascript:;" data-sort="0" class="first alink  o1" :class="menuindex === 1?'crently':''" @click="defaultList()">默认排序</a>
        <a href="javascript:;" type="price" class="alink arrow o1" :class="menuindex === 2?'crently':''" @click="priceUp(prcieType)">
          价格
        <div class="triangle" :class="prcieType?'triangledeg':''"></div>
        </a>
        <a href="javascript:;" type="count" class="alink arrow o1" :class="menuindex === 3?'crently':''">
          销量
          <i></i>
        </a>
      </p>
      <ul class="pager">
        <li>
          <a href="javascript:;">
            <span
              class="pager-icon prev-show disable"
              @click="prePage"
              :class="{ disable: params.page === 1 }"
            >&lt;</span>
          </a>
        </li>
        <li class="mini_nub">
          <span class="current">{{params.page}}</span>
          /{{pageData.last_page}}
        </li>
        <li>
          <a href="javascript:;">
            <span
              class="pager-icon next-show"
              @click="nextPage"
              :class="{disable: params.last_page > 1}"
            >&gt;</span>
          </a>
        </li>
      </ul>
      <div class="fr hp100 show_type">
        <b class="linerow fl"></b>
        <a
          href="javascript:;"
          class="show_gird fl"
          :class="{crently: showType === 'card'}"
          @click="showType = 'card'"
        >
          <svg-icon icon-class="card-type" class-name="card-type-icon"></svg-icon>
        </a>
        <b class="linerow fl"></b>
        <a
          href="javascript:;"
          class="show_line fl"
          :class="{crently: showType === 'list'}"
          @click="showType = 'list'"
        >
          <svg-icon icon-class="list-type" class-name="list-type-icon"></svg-icon>
        </a>
        <b class="linerow fl"></b>
      </div>
    </div>
    <div class="bd1 btnone plr20 ptb10 m-screen-brandPage">
      <label>
        <input type="checkbox" class="vmid mt_3" />新品
      </label>
      <label class="ml30">
        <input type="checkbox" class="vmid mt_3" />热卖商品
      </label>
      <label class="ml30">
        <input type="checkbox" class="vmid mt_3" />送赠品
      </label>
    </div>
    <!--没有提示-->
    <div class="center ptb20 mt40 hidden none_data_list" style="display: none;">
      <i class="ico_fail"></i>
      <div class="f20 fw mt20">非常抱歉，没有找到相关的商品哦~</div>
      <div class="f14 c999 mt10">您可以适当缩短或更改关键词后重新搜索</div>
    </div>
    <!-- 有数据-->
    <div class="has_data_list">
      <div class="clearfix com_show_list listc333" :class="{line_show: showType === 'list'}">
        <div v-for="item in products" :key="item.id" class="item">
          <router-link class="pic" :to="`/detail/${item.id}`" target="_blank">
            <img :src="item.image" alt />
          </router-link>
          <router-link class="title" :to="`/detail/${item.id}`" target="_blank">
            <p
              class="pingp_p"
              :style="'border: 1px solid' + item.brand.color+';'"
            >{{item.brand_name}}</p>
            {{ item.category_name}} {{item.model_name}}
          </router-link>
          <span>
            <i>会员价：</i>
            ¥{{Number(item.discount_price.toString().match(/^\d+(?:\.\d{0,2})?/)) }}
          </span>
          <b class="clearfix">
            <i class="fl">市场价：{{item.price}}</i>
            <i class="fr">{{item.brand_name}}</i>
          </b>
        </div>
      </div>
      <div class="pagenav">
        <!--分页-->
        <el-pagination
          background
          @current-change="handleCurrentChange"
          layout="total, prev, pager, next, jumper"
          :current-page="pageData.current_page"
          :page-size="pageData.per_page"
          :page-count="pageData.last_page>10?10:pageData.last_page"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'
import { products } from '@/api/goods'
export default {
  name: 'BrandList',
  metaInfo: {
    title: '品牌导航',
    titleTemplate: '工流界MRO一站式采购商城'
  },
  data () {
    return {
      products: [],
      pageData: {},
      params: {
        page: 1,
        brand_id: '',
        business_id:'',
        series_id:''
      },
      showType: 'card',
      prcieType: true,
      menuindex: 1
    }
  },
  created () {
    console.log(this.$route)
    this.params.brand_id = this.$route.query.id
    if(this.$route.query.dpid){
      this.params.business_id = this.$route.query.dpid
    }
    if(this.$route.query.seId){
      this.params.series_id = this.$route.query.seId
    }
    this.fetchBrandsProducts()
    this.setHasNav(false)
  },
  methods: {
    ...mapMutations({
      setHasNav: 'app/SET_PAGE_HAS_NAV'
    }),
    async fetchBrandsProducts () {
      const res = await products(this.params)
      this.products = res.data
      console.log(this.usedProducts)
      this.pageData = res.meta
    },
    handleCurrentChange (val) {
      this.params.page = val
      this.fetchBrandsProducts()
    },
    // 上一页
    prePage () {
      this.params.page--
      if (this.params.page < 1) {
        return
      }
      this.fetchBrandsProducts()
    },
    // 下一页
    nextPage () {
      this.params.page++
      this.fetchBrandsProducts()
    },
    async priceUp (type) {
      this.menuindex = 2
      if (type) {
        await this.products.sort((pre, cur) => pre.discount_price - cur.discount_price)
        this.prcieType = false
      } else {
        await this.products.sort((pre, cur) => cur.discount_price - pre.discount_price)
        this.prcieType = true
      }
    },
    defaultList () {
      this.menuindex = 1
      this.fetchBrandsProducts()
    }
  }
}
</script>
<style lang="scss" scoped>
.brand-list {
  width: 1000px;
  margin: 20px auto;
  margin-bottom: 100px;
}
.auc_order {
  background: #f8f8f8;
  height: 38px;
  line-height: 38px;
  position: relative;
  border: 1px solid #e6e6e6;
  z-index: 2;
}

.auc_order p .alink {
  padding: 0 20px;
  float: left;
  border-left: 1px solid #f8f8f8;
  border-right: 1px solid #f8f8f8;
  margin-left: -1px;
  position: relative;
}

.m-screen-brandPage .vmid {
  margin-right: 5px;
}

.auc_order p .alink:hover {
  background: #fff;
  border-right: 1px solid #e6e6e6;
  border-left: 1px solid #e6e6e6;
  z-index: 1;
}

.auc_order p a.first.crently,
.auc_order p a.first {
  border-left: none;
  margin: 0;
}

.auc_order p a.first:hover {
  border-left: none;
}

.auc_order p .crently {
  background: #fff;
  color: #4448f8;
  border-left: 1px solid #e6e6e6;
  border-right: 1px solid #e6e6e6;
  position: relative;
  z-index: 2;
}

.show_type .crently .card-type-icon,
.show_type .crently .list-type-icon {
  fill: #4448f8;
}

.auc_order p span.alink:hover {
  z-index: 3;
}

.auc_order p .arrow i {
  width: 7px;
  height: 4px;
  display: inline-block;
  vertical-align: middle;
  margin: -2px 0 0 5px;
  background-position: -5px -25px;
}

.auc_order p span {
  cursor: pointer;
}

.auc_order p span b a {
  display: block;
}

.auc_order p span b a.crently {
  color: #4448f8;
  border: none;
}

.auc_order p span b {
  position: absolute;
  top: -1px;
  left: 50%;
  margin-left: -60px;
  width: 118px;
  padding: 10px 0;
  line-height: 36px;
  background: #fff;
  border: 1px solid #e6e6e6;
  display: none;
  text-align: center;
}

.auc_show_list {
  width: 1225px;
}

.auc_show_list .item {
  width: 178px;
  float: left;
  border: 1px solid #e6e6e6;
  text-align: center;
  position: relative;
  margin-right: 25px;
  padding: 26px 20px;
  margin-top: 25px;
}

.auc_show_list .item .img {
  width: 160px;
  height: 160px;
  display: block;
  margin: 0 auto;
}

.auc_show_list .item .img img {
  width: 100%;
  height: 100%;
}

.auc_show_list .item .title {
  display: block;
  margin-top: 5px;
}

.auc_show_list .item i {
  display: block;
  color: #ff0000;
  margin-top: 10px;
}

.auc_show_list .item a.go {
  width: 78px;
  border: 1px solid #e6e6e6;
  height: 22px;
  line-height: 22px;
  text-align: center;
  margin: 5px auto 0;
  display: block;
  background: #f5f5f5;
}

.auc_show_list .item a.go:hover {
  background: #4448f8;
  color: #fff;
  border-color: #4448f8;
}

.auc_show_list .item:hover {
  border: 2px solid #4448f8;
  z-index: 1;
  padding: 25px 19px;
}
.com_show_list {
  width: 975px;
  padding-top: 5px;
}

.com_show_list .item {
  width: 180px;
  height: 305px;
  float: left;
  border: 1px solid #e6e6e6;
  position: relative;
  margin-right: 15px;
  padding: 1px 1px 15px;
  margin-top: 15px;
  box-sizing: border-box;
}

.com_show_list .item .pic {
  width: 176px;
  height: 176px;
  display: block;
  margin: 0 auto;
}

.com_show_list .item .pic img {
  width: 100%;
  height: 100%;
  display: block;
}

.com_show_list .item .detail {
  background: #4448f8;
  width: 180px;
  height: 26px;
  text-align: center;
  line-height: 26px;
  position: absolute;
  left: -1px;
  color: #fff;
  bottom: 0;
  opacity: 0;
}

.com_show_list .item:hover .detail {
  bottom: -26px;
  opacity: 1;
}

.com_show_list .item span i {
  color: #999;
  font-size: 12px;
}

.com_show_list .item:hover {
  border: 1px solid #4448f8;
  z-index: 1;
}

.com_show_list .item .title,
.com_show_list .item b,
.com_show_list .item span {
  width: 158px;
  margin: 0 auto;
  display: block;
}

.com_show_list .item b {
  margin-top: 20px;
  color: #999;
}

.com_show_list .item span {
  color: #ff0000;
  margin-top: 10px;
  font-size: 20px;
}

.com_show_list .item .title {
  margin-top: 5px;
  height: 40px;
  overflow: hidden;
}

.com_show_list.line_show {
  width: 96px;
  margin-top: 0;
}

.com_show_list.line_show .item:hover .detail {
  right: 0;
  top: 50%;
  color: #666;
}

.com_show_list.line_show .item .detail {
  background: #f5f5f5;
  border: 1px solid #e6e6e6;
  position: absolute;
  right: 0;
  left: auto;
  top: 50%;
  width: 98px;
  height: 28px;
  line-height: 28px;
  display: none;
  text-align: center;
  margin-top: -15px;
  border-radius: 0;
}

.com_show_list.line_show .item .detail:hover {
  background: #4448f8;
  border-color: #4448f8;
  color: #fff;
}

.com_show_list.line_show .item {
  width: 840px;
  position: relative;
  height: 100px;
  padding: 20px 0 20px 120px;
  border: none;
  border-bottom: 1px solid #e6e6e6;
  box-sizing: content-box;
}

.com_show_list.line_show .item .pic {
  width: 98px;
  height: 98px;
  border: 1px solid #e6e6e6;
  position: absolute;
  left: 0;
  top: 20px;
}

.com_show_list.line_show .item a.title {
  font-size: 14px;
  height: auto;
}

.com_show_list.line_show .item .title,
.com_show_list.line_show .item b,
.com_show_list.line_show .item span {
  display: block;
  margin: 0;
  width: auto;
}

.com_show_list.line_show .item span {
  margin-top: 10px;
}

.com_show_list.line_show .item .detail {
  display: block;
}

.com_show_list.line_show .item b {
  position: absolute;
  bottom: 20px;
}

.com_show_list.line_show .item b i.fr {
  float: left;
  margin-left: 20px;
}

a.show_line,
a.show_gird {
  width: 38px;
  height: 38px;
  display: inline-block;
  text-align: center;
}

a.show_line:hover,
a.show_line.crently,
a.show_gird:hover,
a.show_gird.crently {
  background: #fff;
}

a.show_line i,
a.show_gird i {
  width: 12px;
  height: 12px;
  display: inline-block;
}

a.show_gird i {
  background-position: -38px -364px;
}

a.show_line i {
  background-position: -38px -379px;
}

a.show_gird:hover i,
a.show_gird.crently i {
  background-position: -51px -364px;
}

a.show_line:hover i,
a.show_line.crently i {
  background-position: -51px -379px;
}
.pagenav {
  margin: 30px auto;
  text-align: center;
}
.pager {
  float: right;
  line-height: 38px;
}
.pager li {
  float: left;
  height: 38px;
}
.pager li a {
  display: block;
  float: left;
  height: 38px;
  padding: 0 15px;
}
.pager-icon {
  color: #222222;
}
.pager-icon.disable {
  color: #aaaaaa;
}
.pingp_p {
  display: inline-block;
  padding: 1px 4px;
}
.triangle{
  width: 0;
  height: 0;
  border-style: solid;
  box-sizing: border-box;
  border-width: 0 8px 8px ;
   border-color: transparent transparent #c5c5c5 transparent;
   display: inline-block;
}
.triangledeg{
  transform:rotate(180deg)
}
</style>
